//
//  DeviceDetailFeature1Cell.m
//  DYLYJ
//
//  Created by JM on 15/11/13.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "DeviceDetailFeature1Cell.h"
#import "DYAudioPlay.h"
#import "YYCategories.h"
@implementation DeviceDetailFeature1Cell

+ (NSString *)xib {
    return @"DeviceDetailFeature1Cell";
}
+ (NSString *)ID {
    return @"DeviceDetailFeature1Cell";
}
+ (instancetype)cell {
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:[DeviceDetailFeature1Cell xib] owner:nil options:nil] ;
    DeviceDetailFeature1Cell * cell = [nibs firstObject];
    cell.backgroundColor = [UIColor clearColor];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.tintColor = [UIColor clearColor];
    return cell;
}
- (CGFloat)height {
    NSString *model = [UIDevice currentDevice].machineModel;
    if ([model hasPrefix:@"iPhone"]) {
        if ([model hasPrefix:@"iPhone4"])
            return 330;
        else if ([model hasPrefix:@"iPhone5"])
            return 390;
//        else if ([model hasPrefix:@"iPhone6"])
//        else if ([model hasPrefix:@"iPhone7,1"]) size = CGSizeMake(1080, 1920);
//        else if ([model hasPrefix:@"iPhone7,2"]) size = CGSizeMake(750, 1334);
    } else if ([model containsString:@"iPad"]) {
        return 335;
    }
    //return 390;443 53
    return self.frame.size.height;//iphone6
}
- (void)setDevice:(Device *)device; {
    _device = device;
    self.upButton.selected = _device.isOpen_On;
    self.downButton.selected = _device.isClose_On;
    self.stopButton.selected = _device.isStop_On;
    self.lightButton.selected = _device.isLED_On;
    self.dryButton.selected = _device.isHonggan_On;
    self.airDryButton.selected = _device.isFenggan_On;
    self.xiaoduButton.selected = _device.isXiaodu_On;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 点击 滑动等事件

- (void)animalRock: (UIView *)view {
    
//    view.centerX -= 30;
//    [UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:0.1 initialSpringVelocity:0 options:0 animations:^{
//        view.centerX += 30;
//    } completion:^(BOOL finished) {
//        
//    }];
}
- (IBAction)clickUp:(UIButton *)sender {
//    self.stopButton.selected = NO;
//    self.downButton.selected = NO;
//    self.upButton.selected = NO;
//        sender.selected = YES;
    [self animalRock:sender];
//    _device.isClose_On = NO;
//    _device.isOpen_On = YES;
//    _device.isStop_On = NO;
    [[DYAudioPlay sharedDYAudioPlay] playUpDownStop];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdUp];
    }
 
}
- (IBAction)clickStop:(UIButton *)sender {
//    self.stopButton.selected = NO;
//    self.downButton.selected = NO;
//    self.upButton.selected = NO;
//        sender.selected = YES;;
    
    [self animalRock:sender];
//      _device.isStop_On = YES;
    [[DYAudioPlay sharedDYAudioPlay] playUpDownStop];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdStop];
    }
}

- (IBAction)clickDown:(UIButton *)sender {
//    self.stopButton.selected = NO;
//    self.downButton.selected = NO;
//    self.upButton.selected = NO;
//        sender.selected = YES;
    
    [self animalRock:sender];
//    _device.isClose_On = YES;
//    _device.isOpen_On = NO;
//     _device.isStop_On = NO;
    [[DYAudioPlay sharedDYAudioPlay] playUpDownStop];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdDown];
    }
}
- (IBAction)clickLight:(UIButton *)sender {
//    NSLog(@"sender.selected:%d",sender.selected);
//    sender.selected = !sender.selected;
//    NSLog(@"后sender.selected:%d",sender.selected);
//     _device.isLED_On = sender.selected;
      [[DYAudioPlay sharedDYAudioPlay] playOtherSound];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdLight];
    }
}

- (IBAction)clickDry:(UIButton *)sender {
//    BOOL fff  = !sender.selected;
//    sender.selected = fff;
//       _device.isHonggan_On = self.dryButton.selected;
       [[DYAudioPlay sharedDYAudioPlay] playOtherSound];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdHongGan];
    }
    
}
- (IBAction)clickAirDry:(UIButton *)sender {
//    sender.selected = !sender.selected;
//     _device.isFenggan_On = sender.selected;
          [[DYAudioPlay sharedDYAudioPlay] playOtherSound];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdFengGan];
    }
}
- (IBAction)clickDisinfection:(UIButton *)sender {
//    sender.selected = !sender.selected;
//    _device.isXiaodu_On = sender.selected;
        [[DYAudioPlay sharedDYAudioPlay] playOtherSound];
    if ([self.delegate respondsToSelector:@selector(didDeviceClickCmd:)]){
        [self.delegate didDeviceClickCmd:DevieClickCmdXD];
    }
  
}

- (void)didReceiveMessage:(id)message withtype:(NSString *)aSMSType {
    Device *source = message;
    if ([_device.macAddress isEqualToString:source.macAddress]){
        [self setDevice:source];
    }
}

@end
